package com.tairanchina.joat.groovy

import com.tairanchina.joat.*
import com.tairanchina.joat.exception.JoatExecuteException
import com.tairanchina.joat.exception.JoatLifecycleException

/**
 * Created by 周靖捷 on 2016/10/10.
 */
@AnnotationPluginMeta(
        version = "1.0",
        installMode = PluginInstallMode.DECORATOR_MODE,
        pluginId = "com.tairanchina.joat.groovy.DemoDecoratorGroovyPlugin"
)
@Decorator(value = "com.tairanchina.joat.groovy.DemoGroovyPlugin")
class DemoDecoratorGroovyPlugin extends DecoratorPlugin {

    boolean enabled = true;

    DemoDecoratorGroovyPlugin(Plugin plugin) {
        super(plugin)
    }

    @Override
    Object execute(PluginVariable variable, PluginEnvironment environment) throws JoatExecuteException {
        if (enabled) {
            String helloworlds = variable.get("helloworlds");
            println("decorate.print"+helloworlds);
            return plugin.execute(variable, environment);
        }
        return null;
    }

    @Override
    void init() throws JoatLifecycleException {

    }

    @Override
    void load() throws JoatLifecycleException {

    }

    @Override
    void run() throws JoatLifecycleException {

    }

    @Override
    void disable() {
        this.enabled = false;
    }

    @Override
    void enable() {
        this.enabled = true;
    }

    @Override
    void stop() throws JoatLifecycleException {

    }

    @Override
    void destroy() throws JoatLifecycleException {

    }
}
